package cn.iocoder.yudao.module.system.service.officeinfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.officeinfo.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.officeinfo.SeatinfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.system.dal.mysql.officeinfo.SeatinfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 办公室座位信息 Service 实现类
 *
 * @author Warren365
 */
@Service
@Validated
public class SeatinfoServiceImpl implements SeatinfoService {

    @Resource
    private SeatinfoMapper seatinfoMapper;

    @Override
    public Long createSeatinfo(SeatinfoSaveReqVO createReqVO) {
        // 插入
        SeatinfoDO seatinfo = BeanUtils.toBean(createReqVO, SeatinfoDO.class);
        seatinfoMapper.insert(seatinfo);
        // 返回
        return seatinfo.getId();
    }

    @Override
    public void updateSeatinfo(SeatinfoSaveReqVO updateReqVO) {
        // 校验存在
        validateSeatinfoExists(updateReqVO.getId());
        // 更新
        SeatinfoDO updateObj = BeanUtils.toBean(updateReqVO, SeatinfoDO.class);
        seatinfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteSeatinfo(Long id) {
        // 校验存在
        validateSeatinfoExists(id);
        // 删除
        seatinfoMapper.deleteById(id);
    }

    private void validateSeatinfoExists(Long id) {
        if (seatinfoMapper.selectById(id) == null) {
            throw exception(SEATINFO_NOT_EXISTS);
        }
    }

    @Override
    public SeatinfoDO getSeatinfo(Long id) {
        return seatinfoMapper.selectById(id);
    }

    @Override
    public PageResult<SeatinfoDO> getSeatinfoPage(SeatinfoPageReqVO pageReqVO) {
        return seatinfoMapper.selectPage(pageReqVO);
    }

}